package com.xdb.presistence.metadata;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xdb.presistence.index.XDBIndex;
import com.xdb.presistence.table.XDBTable;
/**
 * 表所对应的元信息
 * @author woate
 *
 */
public class TableMetadata {
	String name;
	/**
	 * 按顺序描述了表中存放列的名称
	 */
	List<String> columns = new ArrayList<String>();
	String[] pks;
	/**
	 * 存放了描述列类型的数据
	 */
	Map<String, ColumnMetadata> columnsDataType = new HashMap<String, ColumnMetadata>();
	/**
	 * 存放了与表所关联的索引信息
	 */
	List<XDBIndex> indexs = new ArrayList<XDBIndex>();
	
	XDBTable table;
	
	String sql;
	
	public XDBTable getTable() {
		return table;
	}
	public void setTable(XDBTable table) {
		this.table = table;
	}
	public int addColumn(ColumnMetadata colmetadata){
		columns.add(colmetadata.getName());
		columnsDataType.put(colmetadata.getName(), colmetadata);
		return columns.size();
	}
	public List<XDBIndex> getIndexs() {
		return indexs;
	}
	public int addIndex(XDBIndex index){
		indexs.add(index);
		return indexs.size();
	}
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	public List<String> getColumns() {
		return columns;
	}
	public String getColumn(int index) {
		return columns.get(index);
	}
	public ColumnMetadata getColumnDataType(String name) {
		return columnsDataType.get(name);
	}
	
	public Map<String, ColumnMetadata> getColumnsDataType() {
		return columnsDataType;
	}
	public XDBIndex getIndex(int index) {
		return indexs.get(index);
	}
	
	public int getIndexSize(){
		return indexs.size();
	}
	public String getSql() {
		return sql;
	}
	public void setSql(String sql) {
		this.sql = sql;
	}
	public String[] getPks() {
		return pks;
	}
	public void setPks(String[] pks) {
		this.pks = pks;
	}
	
}
